﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_RoomBookForm04
 * 类型：       控制层
 * 功能说明：   入住信息登入页面
 * 作者：       谈震鸣
 * 创建日期：   2007/09/04
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Master.Dao;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.System;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Utils;

public partial class App_Input_RoomBookForm04 : System.Web.UI.Page
{
    #region Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {
        //MultiView1.SetActiveView(View1); 
        if (IsPostBack == false)
        {
            if (Context.Items["APARTMENT_NO"] != null) ViewState["APARTMENT_NO"] = (string)Context.Items["APARTMENT_NO"];
            GetContext();
        }
        txtApartmentNo.Text = (string)ViewState["APARTMENT_NO"];
        SetGridView(txtApartmentNo.Text.Trim());
    }
    #endregion

    #region 确定按钮
    //确定按钮
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (ComValidator1.DoValidator())
        {
            if (CheckImf(txtApartmentNo.Text) && ChcekPerson(txtPersonNo.Text) && CheckRoom(txtApartmentNo.Text, txtPersonNo.Text.Trim()))
            {
                lblStatusNo.Text = SetStatusNo((string)ViewState["APARTMENT_NO"]);
                MultiView1.SetActiveView(View2);
            }
        }
    }
    #endregion

    #region 返回按钮
    //返回按钮
    protected void Button5_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View1);
    }
    #endregion

    #region 检查房间编号是否存在
    /*
     *名称： CheckImf
     *功能： 检查信息是否存在
     *参数： str
     *返回： 无
     *说明： 无
     */
    private bool CheckImf(string str)
    {
        MstApartmentBean dataBean = new MstApartmentBean();
        dataBean.ApartmentNo = str;
        ApartmentDao Dao = new ApartmentDao();
        dataBean = Dao.Load(dataBean);
        if (dataBean != null)
        {
            lblApartmentNo.Text = dataBean.ApartmentNo.ToString();
            lblLocation.Text = dataBean.Location;
            lblMemo.Text = dataBean.Memo;
            return true;
        }
        else
        {
            string strErr = HttpContext.GetGlobalResourceObject("Message", "E0203") as string;
            ((Design_MasterPage)this.Master).InfoMessage = strErr.Replace("{0}", "房间");
            return false;
        }
    }
    #endregion

    #region 人员编号是否存在
    /*名称： ChcekPerson
     *功能： 人员编号是否存在
     *参数： str
     *返回： 无
     *说明： 无
     */
    private bool ChcekPerson(string str)
    {
        ApartmentStatusBean dataBean = new ApartmentStatusBean();
        RoomBookDao Dao = new RoomBookDao();
        dataBean.MemberNo = str.Trim();
        dataBean = Dao.ApartmentStatusLoad(dataBean);
        if (dataBean != null)
        {
            lblPersonNo.Text = dataBean.MemberNo;
            lblName.Text = dataBean.Name;
            return true;
        }
        else
        {
            string strErr = HttpContext.GetGlobalResourceObject("Message", "E0203") as string;
            ((Design_MasterPage)this.Master).InfoMessage = strErr.Replace("{0}", "人员编号");
            return false;

        }

    }
    #endregion

    #region 登记按钮
    //登记按钮
    protected void Button4_Click(object sender, EventArgs e)
    {
        if (CheckRoom(lblApartmentNo.Text.Trim(), lblPersonNo.Text.Trim()))
        {
            ApartmentStatusBean dataBean = new ApartmentStatusBean();
            RoomBookDao Dao = new RoomBookDao();
            dataBean.MemberNo = lblPersonNo.Text.Trim();
            dataBean.ApartmentNo = lblApartmentNo.Text.Trim();
            SysUserManager manager = new SysUserManager(Context);
            SysUserBean sysUserBean = manager.getSysUserBean();
            MstSysUserBean mstSysUserBean = sysUserBean.getMstSysUserBean();
            dataBean.UserId = mstSysUserBean.SysUserId;
            //dataBean.UserId = "tan";
            dataBean.StatusNo = "02";
            dataBean.MemberStatus = "0";
            dataBean.MemberStatusW="1";
            dataBean.Memo = txtMemo.Text;
            if (Dao.ListUpdateApartmentStatus04(dataBean) == 1)
            {
                ((Design_MasterPage)this.Master).InfoMessage = HttpContext.GetGlobalResourceObject("Message", "I0001") as string;
                SetContext();
                // Server.Transfer("RoomBookSrhForm.aspx");
                ControllerUtils.Transfer(Context, "~/App/Input/RoomBookSrhForm.aspx");
            }
        }
    }
    #endregion

    #region 该会员是否已经订房或入住
    /*名称： CheckRoom
     *功能： 该会员是否已经订房或入住
     *参数： str
     *返回： 无
     *说明： 无
     */
    private bool CheckRoom(string str1, string str2)
    {
        ApartmentStatusBean dataBean = new ApartmentStatusBean();
        RoomBookDao Dao = new RoomBookDao();
        dataBean.MemberNo = str2.Trim();
        dataBean.ApartmentNo = str1.Trim();
        IList dataList = Dao.FindByPersonStatus04(dataBean);
        if (dataList.Count > 0)
        {

            return true;
        }
        else
        {
            //string strErr = HttpContext.GetGlobalResourceObject("Message", "E0203") as string;
            ((Design_MasterPage)this.Master).InfoMessage = HttpContext.GetGlobalResourceObject("Message", "I0012") as string;
            return false;
        }
    }
    #endregion

    #region 显示状态
    private string SetStatusNo(string str)
    {
        RoomBookApartBean dataBean = new RoomBookApartBean();
        RoomBookDao Dao = new RoomBookDao();
        dataBean.ApartmentNo = str.Trim();
        IList dataList = Dao.ListRoomStatus(dataBean);
        if (dataList.Count > 0)
        {
            RoomBookApartBean dataBean1 = (RoomBookApartBean)dataList[0];
            return dataBean1.ShowStatusChar;
        }
        else
        {
            return string.Empty;
        }
    }
    #endregion

    #region Context传输
    //Get
    private void GetContext()
    {
        // 传递检索内容
        ViewState["InpApartStatus"] = Context.Items["InpApartStatus"];
        ViewState["InpApartStatus"] = Context.Items["InpBuildingNo"];
        ViewState["InpApartType"] = Context.Items["InpApartType"];
        ViewState["InpApartId"] = Context.Items["InpApartId"];
        ViewState["ParamCommand"] = Context.Items["ParamCommand"];

        // 传递分页编号
        ViewState["ParamPageIndex"] = Context.Items["ParamPageIndex"];
    }
    //Set
    private void SetContext()
    {
        // 传递检索内容
        Context.Items["InpApartStatus"] = ViewState["InpApartStatus"];
        Context.Items["InpBuildingNo"] = ViewState["InpApartStatus"];
        Context.Items["InpApartType"] = ViewState["InpApartType"];
        Context.Items["InpApartId"] = ViewState["InpApartId"];
        Context.Items["ParamCommand"] = ViewState["ParamCommand"];

        // 传递分页编号
        Context.Items["ParamPageIndex"] = ViewState["ParamPageIndex"];
    }
    #endregion

    #region 返回按钮
    //返回按钮
    protected void Button3_Click(object sender, EventArgs e)
    {
        SetContext();
        // Server.Transfer("RoomBookSrhForm.aspx");
        ControllerUtils.Transfer(Context, "~/App/Input/RoomBookSrhForm.aspx");
    }
    #endregion

    #region 显示房间入住信息
    private void SetGridView(string str)
    {
        ApartmentStatusBean dataBean = new ApartmentStatusBean();
        RoomBookDao Dao = new RoomBookDao();
        dataBean.ApartmentNo = str.Trim();
        IList dataList = Dao.FindByApartmentStatusNo(dataBean);
        GridView1.DataSource = dataList;
        GridView1.DataBind();
    }
    #endregion

}
